import pandas as pd

# 生成示例数据
data = {
    'datetime': pd.date_range(start='2023-01-01', periods=10, freq='D'),
    'open': [100, 105, 110, 98, 102, 108, 96, 105, 98, 102],
    'high': [105, 110, 115, 100, 108, 112, 100, 112, 102, 110],
    'low': [98, 102, 105, 95, 98, 100, 92, 98, 92, 96],
    'close': [102, 108, 112, 96, 105, 110, 98, 110, 96, 105],
    'volume': [1000, 1200, 1300, 800, 900, 1100, 700, 1000, 600, 800]
}

df = pd.DataFrame(data)
df.set_index('datetime', inplace=True)

# 计算均线
sma_period = 5  # 均线周期
df['sma'] = df['close'].rolling(window=sma_period).mean()

# 打印结果
print(df)
